/**
 * sleep状态处理中断
 */
public class ThreadExample8 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            while(!Thread.currentThread().isInterrupted()) {
                try {
                    System.out.println(Thread.currentThread().getName() + " : I am alive!");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("sleep interrupt~");
                    break;
                }
            }
            try {
                System.out.println(Thread.currentThread().getName() + " : I am leave in just one second!!");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("I am leave~");
        }, "I'm spider man~");

        thread.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());

        System.out.println("send interrupt~");
        thread.interrupt();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());
    }
}

/**
 * I'm spider man~ : I am alive!
 * I'm spider man~ : I am alive!
 * I'm spider man~ : I am alive!
 * I'm spider man~: 活着: true
 * send interrupt~
 * sleep interrupt~
 * I'm spider man~ : I am leave in just one second!!
 * java.lang.InterruptedException: sleep interrupted
 * 	at java.base/java.lang.Thread.sleep(Native Method)
 * 	at ThreadExample8.lambda$main$0(ThreadExample8.java:10)
 * 	at java.base/java.lang.Thread.run(Thread.java:842)
 * I am leave~
 * I'm spider man~: 活着: false
 */